<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" href="/after/css/bootstrap.min.css">
    <link rel="stylesheet" href="/after/css/laypage.css">
    <script type="text/javascript" src="/after/js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="/after/js/laypage/laypage.js"></script>
    <script type="text/javascript" src="/after/js/layer/layer.js"></script>
    <script type="text/javascript" src="/after/js/vue/vue.min.js"></script>
    <script src="/after/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/after/jquery.validation/1.14.0/messages_zh.min.js"></script>
</head>
<style>
    input.error {
        border: 1px solid red;
    }
</style>
<body>
<div id="app">
<div class="container">
    <form id="ChangePass" method="post" action="/role/ChangePass.do">
        <br/>
        <input type="hidden" class="form-control" id="id" name="id">
        <div class="form-group">
            <label for="pass">新密码：</label>
            <input type="text" class="form-control" id="pass" name="pass">
        </div>
        <div class="form-group">
            <label for="rpass">确认密码：</label>
            <input type="text" class="form-control" id="rpass" name="rpass">
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" onclick="save()" class="btn btn-success">确定</button>
            <button type="button" id="cancelBtn" onclick="calcelBtn()" class="btn btn-success">重置</button>
        </div>
    </form>
</div>
</div>
</body>
</html>

<script>
    var app = new Vue({
        el:'#app',
        data:{
            btype:[]
        }
    })

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    var temp=getQueryString("id")

  /*  var indexNum=temp.indexOf("?");
    temp=temp.substring(0,indexNum);*/
    $("#id").val(temp);


    var Changee = function() {
        if(confirm("是否设置新密码")){
            var pass=$("#pass").val();
            var rpass=$("#rpass").val();
            if (!check().form()) {
                return false;
            }else{
                if(rpass!=pass){
                    layer.msg("新旧密码不一致");
                    return false;
                }else{
                    return true;
                }
            }
        }
    }

    function calcelBtn(){
        console.log("关闭");
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    function save(){
        if(Changee()){
            $("#ChangePass").submit();
//        console.log("123");
            calcelBtn();
        }
    }

    //校验数据是否为空
    function check(){
        return $("#ChangePass").validate({
            rules:{
                pass:{
                    required: true
                },
                rpass:{
                    required: true
                }
            },
            messages:{
                pass:{
                    required: ""
                },
                rpass:{
                    required: ""
                }
            }
        })
    }

</script>